import types from './actionTypes'
import axios from 'axios'
import { fromJS } from "immutable";
const changLogin = (login) => ({
  type: types.CHANGE_LOGIN,
  login
})

export const login = (account, password) => {
  return dispatch => {
    axios.get(`/api/login.json?account=${account}&password=${password}`).then(res => {
      console.log(res)
      const result = res.data.success
      if (result) {
        dispatch(changLogin(true))
      } else {
        alert('fail')
      }
    }).catch(e => {
      console.log(e)
    })
  }
}

export const logout = () => {
  return dispatch => {
    axios.get('/api/logout.json').then(res => {
      dispatch(changLogin(false))
    })
  }
}
